package maps

import (
	"showurl/static-file/kplayer/apis/singles"
	"strings"
	"time"
)

func Jump(name string)  {
	if name == "" {
		name = "8当啊世俗看海般洒付定金阿桑阿森看"
	}
	mediaResp := singles.GetMedia()
	mediaCurrentResp := singles.GetMediaCurrent()
	if mediaResp == nil || mediaCurrentResp == nil {
		panic("获取媒体列表失败")
	}
	now := mediaCurrentResp.CurrentMedia.Unique
	nowIndex := -1
	needFindIndex := -1
	for i, item := range mediaResp.MediaPlayList {
		if strings.Contains(item.Path, name) || name == item.Unique {
			needFindIndex = i
		}
		if now == item.Unique {
			nowIndex = i
		}
	}
	if nowIndex == -1 || needFindIndex == -1 {
		panic("没找到媒体资源")
	}
	if nowIndex == needFindIndex {
		return
	}
	if nowIndex < needFindIndex {
		for i := 0; i < needFindIndex-nowIndex; i++ {
			singles.SkipCurrent()
			time.Sleep(time.Second*2)
		}
		return
	}
	if nowIndex > needFindIndex {
		for i := 0; i < len(mediaResp.MediaPlayList)-nowIndex+needFindIndex; i++ {
			singles.SkipCurrent()
		}
		return
	}
}
